package com.obtk.property.controller;

import com.github.pagehelper.Page;
import com.obtk.property.common.MessageParking;
import com.obtk.property.common.PageResult;
import com.obtk.property.common.Result;
import com.obtk.property.common.StatusCode;
import com.obtk.property.pojo.Parking;
import com.obtk.property.service.ParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/parking")
public class ParkingController {

    @Autowired
    private ParkingService parkingService;
    @RequestMapping("/find")
    public Result find(){
        List<Parking> all = parkingService.selAll();
        System.out.println(all);
        return new Result(true,200,"请求成功adasdasdas",all);
    }
    @RequestMapping("/search")
    public PageResult search(@RequestBody Map searchMap){
        Page<Parking> page = parkingService.search(searchMap);
        return new PageResult(true, StatusCode.OK, MessageParking.Parking_SEARCH_SUCCESS,page.getResult(),page.getTotal());
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Parking parking){
        Boolean add = parkingService.add(parking);
        return new Result(true, StatusCode.OK, MessageParking.Parking_ADD_SUCCESS);
    }
    @RequestMapping("/findById")
    public Result findById(Integer parkingId){
        Parking parking = parkingService.findById(parkingId);
        return new Result(true, StatusCode.OK, MessageParking.Parking_FIND_BY_ID_SUCCESS,parking);
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Parking parking){
        Boolean add = parkingService.update(parking);
        return new Result(true, StatusCode.OK, MessageParking.Parking_UPDATE_SUCCESS);
    }
    // 是否禁用或启用
    @RequestMapping("/updateStatus/{useType}/{parkingId}")
    public Result updateStatus(@PathVariable("useType") String useType, @PathVariable("parkingId") Integer parkingId){
        Boolean flag = parkingService.updateStatus(useType,parkingId);
        return new Result(true, StatusCode.OK, MessageParking.Parking_UPDATE_STATUS_SUCCESS);
    }
    @RequestMapping("/del")
    public Result del(@RequestBody List<Integer> ids){
        Boolean flag = parkingService.del(ids);
        return new Result(true, StatusCode.OK, MessageParking.Parking_DELETE_SUCCESS);
    }
}
